// pages/choose_advising/choose_advising.js

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    chooseList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var list = []
    var obj = {}
    for(var i=0; i<app.globalData.list.length; i++){
      obj={}
      obj['advising']=app.globalData.list[i]
      obj['isChosen']=false
      list.push(obj)
    }
    this.setData({
      chooseList: list
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  preview_advising(e){//查看咨询记录详情（消息记录）
    var index = e.currentTarget.dataset.index
    var advising = this.data.chooseList[index].advising
    var created = advising.created
    var advisorInfoBean = JSON.stringify(advising.advisorInfo)
    wx.navigateTo({
      url: '/pages/message/message?advisorInfoBean='+advisorInfoBean+'&created='+created,//将咨询师信息传至聊天记录页面并跳转
    })
  },

  change_isChosen(e){//选中or取消选中某条咨询记录
    var list = this.data.chooseList
    var index = e.currentTarget.dataset.index
    list[index].isChosen = !list[index].isChosen
    this.setData({
      chooseList: list
    })
  },

  send(){//发送选中的消息记录
    var sendList=[]
    for(var i=0; i<this.data.chooseList.length; i++){//将选中的消息放入sendList
      if(this.data.chooseList[i].isChosen){
        sendList.push(this.data.chooseList[i].advising)
      }
    }
    if(sendList.length>0){//sendList不为空
      app.globalData.chosenRecordList=sendList
      wx.navigateBack({
        delta: 1,
      })
    }else{//sendList为空
      wx.showToast({
        title: '没有选中的记录',
        icon:'none'
      })
    }
    
  }
})